const db = require('../mysql/db')
const jsonData = require('./wineTast.json')
const dataList = jsonData.result.list

dbInsert() 
function dbInsert() {
    dataList.map((item,index)=>{
        dbInsertSingle(item,index)
    })
    db.end()
}
function dbInsertSingle(data,index) {
    db.query(`
    INSERT INTO articles SET 
    articleID = ?,category = ?, title = ?, img = ?, content = ?, 
    brief = ?, publish = ?
    `, [
        data.articleID,
        data.category,
        data.title,
        data.img,
        data.content,
        data.brief,
        data.publish
    ], function (error, results, fields) {
        // 执行SQL语句失败
        if (error) return console.log(error.message);
        // 成功了
        if (results.affectedRows === 1) {
            console.log(`插入第${index}条数据成功！`);
        }
        // db.end()
        return
    });
}
